home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / progjour / 1991 / 02 / term.asm < prev    next >
Assembly Source File  |  1990-10-31  |  2KB  |  117 lines

  1.     title    termination routines
  2.     include    asm.inc
  3.  
  4.     public    enable_exit_intercept
  5.     public    disable_exit_intercept
  6.  
  7. XPB    segment word public 'DATA'    ; full exit routines
  8. XPB    ends
  9. XP    segment word public 'DATA'
  10.     dw    disable_exit_intercept    ; on full exit, disable exit
  11. XP    ends                ;  intercept
  12. XPE    segment word public 'DATA'
  13. XPE    ends
  14.  
  15. XCB    segment word public 'DATA'    ; quick exit routines
  16.     extrn    xcbegin:word
  17. XCB    ends
  18. XC    segment word public 'DATA'
  19. XC    ends
  20. XCE    segment word public 'DATA'
  21.     extrn    xcend:word
  22. XCE    ends
  23.  
  24. DGROUP    group    XPB,XP,XPE,XCB,XC,XCE
  25.  
  26.     .data
  27.     extrn    psp:word
  28.  
  29.     .data?
  30.     extrn    top_of_stack:word
  31.  
  32.  
  33. terminate_offset    dw    ?    ; original terminate address from
  34. terminate_segment    dw    ?    ;  PSP:000A
  35.  
  36.  
  37.     .code
  38.     extn    initterm
  39.  
  40.  
  41. ;;    enable exit intercept
  42. ;
  43. ;    uses    AX,SI,DS
  44. ;
  45. enable_exit_intercept proc
  46.     mov    ds,psp[bp]
  47.     mov    si,0Ah
  48.  
  49.     mov    ax,cs
  50.     cmp    ax,[si+2]
  51.     je    eei1            ;  if exit intercept already set
  52.  
  53.     xchg    ax,[si+2]
  54.     mov    terminate_segment[bp],ax
  55.  
  56.     lea    ax,process_surprise_exit
  57.     xchg    ax,[si]
  58.     mov    terminate_offset[bp],ax
  59.  
  60. eei1:    ret
  61. enable_exit_intercept endp
  62.  
  63.  
  64. ;;    disable exit intercept
  65. ;
  66. ;    uses    AX,SI,DS
  67. ;
  68. disable_exit_intercept proc
  69.     movx    ax,0
  70.     xchg    ax,terminate_segment[bp]
  71.     cmpx    ax,0
  72.     je    dei1            ;  if no exit intercept
  73.  
  74.     mov    ds,psp[bp]        ; restore original terminate address
  75.     mov    si,0Ah
  76.     mov    [si+2],ax
  77.  
  78.     movx    ax,0
  79.     xchg    ax,terminate_offset[bp]
  80.     mov    [si],ax
  81.  
  82. dei1:    ret
  83. disable_exit_intercept endp
  84.  
  85.  
  86. ;;    process surprise exit
  87. ;
  88. process_surprise_exit proc far
  89.     mov    cx,DGROUP        ; access DGROUP via DS (SS != DGROUP)
  90.     mov    ds,cx
  91.     assume    ds:DGROUP
  92.  
  93.     push    terminate_segment    ; set far return to original terminate
  94.     push    terminate_offset    ;  address from PSP:000A
  95.  
  96.     mov    ax,sp            ; save COMMAND.COM's stack pointer
  97.     mov    dx,ss
  98.  
  99.     mov    ss,cx            ; switch to our stack
  100.     mov    sp,top_of_stack
  101.  
  102.     pushf                ; call terminators
  103.     pushm    ax,dx,bp
  104.     movx    bp,0
  105.     lea    di,xcend
  106.     lea    si,xcbegin
  107.     call    initterm
  108.     popm    bp,dx,ax
  109.     popf                ;  (flags aren't changed by intercept)
  110.  
  111.     mov    ss,dx            ; restore COMMAND.COM stack
  112.     mov    sp,ax
  113.     ret
  114. process_surprise_exit endp
  115.  
  116.     end
  117.